#!/usr/bin/env bash

# 安装基本依赖
apt install -y locales wget curl ufw wireless-tools htop \
    build-essential libncurses-dev libgtk-3-dev \
    libatk1.0-dev libcairo2-dev libx11-dev libxpm-dev \
    libxt-dev python3-dev python3-distutils ruby-dev \
    lua5.4 liblua5.4-dev libperl-dev tcl-dev git screen jq \
    libjq1 libonig5 gawk flex binutils-dev libelf-dev texinfo

# 设置时区为上海
timedatectl set-timezone Asia/Shanghai

# 添加 locale 配置
cat << EOF >> /etc/locale.gen
zh_CN GB2312
zh_CN.GB18030 GB18030
zh_CN.GBK GBK
zh_CN.UTF-8 UTF-8
en_US ISO-8859-1
en_US.ISO-8859-15 ISO-8859-15
en_US.UTF-8 UTF-8
EOF

# 清空 motd、issue 和 issue.net 文件内容
echo "" > /etc/motd
echo "" > /etc/issue
echo "" > /etc/issue.net

# 生成 locale
locale-gen

# 配置默认 locale
cat << EOF > /etc/default/locale
LANG=zh_CN.GB2312
LC_CTYPE="zh_CN.UTF-8"
LC_NUMERIC="zh_CN.UTF-8"
LC_TIME="zh_CN.UTF-8"
LC_COLLATE="zh_CN.UTF-8"
LC_MONETARY="zh_CN.UTF-8"
LC_MESSAGES="zh_CN.UTF-8"
LC_PAPER="zh_CN.UTF-8"
LC_NAME="zh_CN.UTF-8"
LC_ADDRESS="zh_CN.UTF-8"
LC_TELEPHONE="zh_CN.UTF-8"
LC_MEASUREMENT="zh_CN.UTF-8"
LC_IDENTIFICATION="zh_CN.UTF-8"
LC_ALL=zh_CN.UTF-8
EOF

# 应用默认 locale 配置
source /etc/default/locale

# 配置 PATH 环境变量和代理设置
echo 'export PATH="/usr/bin:/usr/local/bin:$PATH"' >>/etc/profile
echo 'alias unsetproxy="unset ALL_PROXY"' >>/etc/profile
echo 'alias setproxy="export ALL_PROXY=socks5://127.0.0.1:7890"' >>/etc/profile

# 应用 profile 配置文件
source /etc/profile

# 手动配置语言环境（如果不执行命令配置，可能就会不成功）
dpkg-reconfigure locales

# 添加环境变量和代理设置到 profile 文件中
cat << EOF >> /etc/profile
# Environment Variable
export PATH="/usr/bin:/usr/local/bin:$HOME/go/bin:$PATH"
export LC_ALL="zh_CN.UTF-8"
export LANG="zh_CN.UTF-8"
export LANGUAGE="zh_CN.UTF-8"
export EDITOR="vim"

# clash and proxy settings
export clashdir="/usr/share/clash"
alias clash="bash /usr/share/clash/clash.sh"
EOF

# 重启系统以应用更改
reboot
